package com.qf.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.qf.pojo.DtsTopic;
import com.qf.service.DtsTopicService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/topic")
public class AdminTopicController {

    @Autowired
    DtsTopicService topicService;

    @PostMapping("/update")
    public Object update(@RequestBody DtsTopic topic){
        topicService.update(topic);

        return ResponseUtil.ok();
    }

    @PostMapping("/delete")
    public Object delete(@RequestBody DtsTopic topic){
        topicService.delete(topic);

        return ResponseUtil.ok();
    }

//    @PostMapping("/create")
//    public Object create(@RequestBody Map<String,Object> map){
//        String title = (String) map.get("title");
//        String subtitle = (String) map.get("subtitle");
//        String context = (String) map.get("context");
//        String price = (String) map.get("price");
//        String readCount = (String) map.get("readCount");
//        String picUrl = (String) map.get("picUrl");
//
//
//        topicService.insert(title,subtitle,context,price,readCount,picUrl);
//
//        return ResponseUtil.ok(map);
//    }

    //对象接收返回数据
    @PostMapping("/create")
    public Object create(@RequestBody DtsTopic topic){
        topicService.insert(topic);

        return ResponseUtil.ok(topic);
    }

    @GetMapping("/list")
    public Object list(@RequestParam(value = "page",required = false,defaultValue = "1")Integer page,
                       @RequestParam(value = "limit",required = false,defaultValue = "20")Integer limit,
                       @RequestParam(value = "sort",required = false,defaultValue = "add_time")String sort,
                       @RequestParam(value = "order",required = false,defaultValue = "desc")String order,
                       String title,String subtitle){
        Map<String,Object> data = topicService.findByPage(page,limit,sort,order,title,subtitle);

        return ResponseUtil.ok(data);

    }
}
